package com.iteye.taobao.app;

import com.founder.android.util.AndroidTaobaoClient;
import com.founder.android.util.TaobaoClientListener;
import com.taobao.api.ApiException;
import com.taobao.api.TaobaoResponse;
import com.taobao.api.request.TimeGetRequest;
import com.taobao.api.response.TimeGetResponse;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TaobaoSellerAppActivity extends Activity implements TaobaoClientListener {
	
    protected static String appkey = "12464940";
    
    protected static String sandbox_secret = "sandbox0fb0745cee22e0ed23072af03";

    protected static String secret = "a9560590fb0745cee22e0ed23072af03";
    
    protected static String testUrl = "http://gw.api.tbsandbox.com/router/rest";//沙箱环境调用地址
    
    private TextView message;
    
    private AndroidTaobaoClient client;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        message = (TextView)findViewById(R.id.message);
        client = new AndroidTaobaoClient(testUrl, appkey, sandbox_secret);//
        
        
        Button queryTime = (Button)findViewById(R.id.queryTime);
        queryTime.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
		        TimeGetRequest request = new TimeGetRequest();
		        try {
					client.execute(request, TaobaoSellerAppActivity.this);
				} catch (ApiException e) {
					message.setText("Error:" + e.getMessage());
					Log.e("TaobaoSellerAppActivity", "Error:", e);
				}
			}
		});
    }

	@Override
	public void onResponseFailed(Throwable error) {
		message.setText("Error:" + error);
		Log.e("TaobaoSellerAppActivity", "Error:", error);
	}

	@Override
	public void onResponseSuccess(TaobaoResponse response) {
		TimeGetResponse timeResponse = (TimeGetResponse)response;
		Log.d("TaobaoSellerAppActivity", "success:" + timeResponse.getTime());
		message.setText("success:" + timeResponse.getTime());
	}
}